//
//  CustomerDetailViewController.m
//  CommodityManager
//
//  Created by lanou3g on 15/5/28.
//  Copyright (c) 2015年 libertyair. All rights reserved.
//

#import "CustomerDetailViewController.h"

@interface CustomerDetailViewController ()

@end

@implementation CustomerDetailViewController


- (void)viewDidLoad {
    [super viewDidLoad];
   
    // Do any additional setup after loading the view from its nib.
   //导航栏标题
   self.navigationController.title=@"新增客户";
    //视图背景图片
    self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"34_bg_denglu"]];
#pragma mark---------------导航栏按钮设置
    [self setupBarButtoon];
    //设置代理
    _cNameTF.delegate=self;
    _cSexTF.delegate=self;
    _cPhoneNumTF.delegate=self;
    _cShopTF.delegate=self;
    _cAddressTF.delegate=self;
    _cRemarksTF.delegate=self;
    _cTimeTF.delegate=self;
    
}
#pragma mark---------------导航栏按钮设置
-(void)setupBarButtoon{
//左边按钮返回客户管理
    UIBarButtonItem *leftBI=[[UIBarButtonItem alloc] initWithTitle:@"客户管理" style:UIBarButtonItemStylePlain target:self action:@selector(returnCustomerVC:)];
    self.navigationItem.leftBarButtonItem=leftBI;
//右边按钮,保存添加的客户信息
    UIBarButtonItem *rightBI=[[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(preserveCustomerInformation:)];
    self.navigationItem.rightBarButtonItem=rightBI;

}
#pragma mark---------------左边按钮点击事件的实现,返回到客户管理页面
-(void)returnCustomerVC:(UIBarButtonItem *)BI{
    
    [self.navigationController popViewControllerAnimated:YES];

}
#pragma mark----------------右边按钮点击事件的实现,保存客户信息
-(void)preserveCustomerInformation:(UIBarButtonItem *)BI{
    
    CustomerDetailModel *customer=[[CustomerDetailModel alloc] init];
    customer.cName=_cNameTF.text;
    customer.cPhoneNum=_cPhoneNumTF.text;
    customer.cRemarks=_cRemarksTF.text;
    //如果姓名为空或者号码错误时弹出提示框

    if (_cNameTF.text.length!=0 && _cPhoneNumTF.text.length!=0 ) {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"添加成功啦!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        
        //如果添加成功,返回到客户管理页面
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"输入有误,请重新输入!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"好的", nil];
        [alert show];
        //如果输入有误,把电话号码置为空
        _cPhoneNumTF.text=@"";
    }
    
}

#pragma mark-----------------输入框的键盘回收方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
